package com.i2works.smartluolong.web.controller.common;


import com.i2works.smartluolong.utils.base.MsgEnum;
import com.i2works.smartluolong.utils.common.EmailUtil;
import com.i2works.smartluolong.utils.entity.Result;
import com.i2works.smartluolong.web.utils.BaseModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 邮件发送
 *
 * @author Liu Yutao
 * @className EmailController
 * @email koal@vip.qq.com
 * @date 2016/5/25 12:54
 */


@Controller
@RequestMapping("/email")
public class EmailController extends BaseModule {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    private EmailUtil emailUtil;


    /**
     * 邮件发送接口
     *
     * @param userName 接收者姓名
     * @param email    接收者邮箱
     * @param sendType 邮件类型
     */
    @PostMapping(value = "/send")
    @ResponseBody
    public Result sendEmail(
            @RequestParam(value = "userName", required = false) String userName,
            @RequestParam(value = "email", required = false) String email,
            @RequestParam(value = "sendType", required = false) Integer sendType
    ) {
        Result result = new Result();
        try {
            emailUtil.execute(100, userName, email, sendType);
        } catch (Exception e) {
            logger.error("发送邮箱异常：", e.getMessage());
            result.setSuccess(false);
            result.setMsg(MsgEnum.SYSTEM_ERROR.getMsg());
        }
        return result;
    }


}
